package com.course.web.page;

import com.course.web.view.AccessDeniedView;
import com.vaadin.server.VaadinRequest;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.*;

/**
 * Created by Justin on 2017/5/31.
 */
@SpringUI
public class HomeUI extends UI {

    @Override
    protected void init(VaadinRequest request) {
        Panel panel = new Panel("Please choose your ID type");
        VerticalLayout root = new VerticalLayout();
        Button admin = new Button("Manager");
        Button teach = new Button("Teacher");
        panel.setContent(root);
        root.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
        root.addComponent(admin);
        root.addComponent(teach);
        setContent(panel);
        setSizeFull();
        getNavigator().setErrorView(AccessDeniedView.class);
        getPage().setTitle("首页");

        admin.addClickListener(event -> jump("/admin"));
        teach.addClickListener(event -> jump("/teach"));
    }

    private void jump(String url) {
        getPage().setLocation(url);
    }
}
